use std::io::Result;
use retsu_rs::{
    async_chunk::extract_refill::AsyncChunk,
    chunker::fastcdc::{ConstConfig, NoStateConstConf},
};
use tokio::{fs::File, io::BufReader};
use tokio_util::compat::TokioAsyncReadCompatExt;

#[tokio::main]
async fn main() -> Result<()> {
    let file_name = include_str!("../tmp-test-file.name").trim();
    let f = File::open(file_name).await?;
    let size = f.metadata().await?.len();

    let f_bufed = BufReader::with_capacity(64 * 1024, f);

    let mut ck = AsyncChunk::new(
        f_bufed.compat(),
        NoStateConstConf(ConstConfig::<2048, 65536, 8192, 1>::new()),
    );

    let mut n = 0;
    let mut combined = 0;
    while let Some((chunk, wfp)) = ck.chunk_next_ref_mut().await? {
        let ckh = gxhash::gxhash64(chunk, 12);
        combined += ckh;
        n += 1;
    }
    println!(
        "Avg chunk size: {size}/{n}={}\nffp: {combined}",
        size as f64 / n as f64
    );
    Ok(())
}
